package day6;

import java.util.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author oldliu
 * @since 1.0
 */
public class MapTest {
    public static void main(String[] args) {
        String str="akdsjfwoesdfkjsfsdfsdfhsdlfsdghrawdef";
        Map<Character,Integer> map=new HashMap<>();
        char[]cr=str.toCharArray();
        for(char c:cr){
            Integer i=map.get(c);
            if(i==null)
                i=0;
            i++;
            map.put(c,i);
        }
        //
        //Set<Map.Entry<Character, Integer>> entries = map.entrySet();
        List<Map.Entry<Character, Integer>> list=new ArrayList<>(map.entrySet());
        Collections.sort(list,new MyCom());
        for(Map.Entry<Character, Integer> k:list)
            System.out.println(k.getKey()+" "+k.getValue());
    }
}
class MyCom implements Comparator<Map.Entry<Character, Integer>>{

    @Override
    public int compare(Map.Entry<Character, Integer> o1, Map.Entry<Character, Integer> o2) {
        return o2.getValue()-o1.getValue();
    }
}